
const Mock=require('mockjs')
const bodyParser=require('body-parser')
const data=Mock.mock({
    "list":{
        "banner|5-6":["@image(300x180,@color)"],
        "lists|100-300":[{
            "img":"@image(100x100,@color)",
            "title":"@ctitle",
            "desc":"@cword(10,15)",
            "id":"@id",
            "type|0-3":1,
            "city":"@city(true)"
        }]
    }
})

module.exports=app=>{
    app.use(bodyParser.json())
    app.post('/api/list',(req,res)=>{
        let {tabKey,curret}=req.body
        console.log(req.body)
        // eslint-disable-next-line no-const-assign
        tabKey=tabKey*1
        res.send({
            code:200,
            data:data.list.lists.filter(item=>item.type===tabKey).filter((v,i)=>i<curret*10)
        })
    })
    app.post('/api/detail',(req,res)=>{
        const {id}=req.body
        console.log(id)
        const newdata=data.list.lists.find(item=>item.id===id)
        console.log(newdata)
        res.send({
            code:200,
            data:newdata
        })
    })
}

